library(jsonlite)
library(dplyr)
library(foreign)
library(maptools)
library(foreign)
library(classInt)
library(RColorBrewer)
library(ggplot2)
library(plyr)
library(lsr)
library(bear)
library(MASS)
library(sandwich)
library(plm)
library(ggmap)
library(rgeos)
library(rgdal)
install.packages("rgdal")
install.packages("lsr")
install.packages("bear")
install.packages("MASS")
install.packages("sandwich")
install.packages("plm")
install.packages("ggmap")
install.packages("rgeos")
install.packages("MASS")
install.packages("MASS")
library(jsonlite)
library(dplyr)
library(foreign)
library(maptools)
library(foreign)
library(classInt)
library(RColorBrewer)
library(ggplot2)
library(plyr)
library(lsr)
library(bear)
library(MASS)
library(sandwich)
library(plm)
library(ggmap)
library(rgeos)
library(rgdal)
#install.packages("jsonlite")
#install.packages("dplyr")
#install.packages("foreign")
#install.packages("maptools")
#install.packages("foreign")
#install.packages("classInt")
#install.packages("RColorBrewer")
#install.packages("ggplot2")
#install.packages("plyr")
#install.packages("lsr")
#install.packages("bear")
#install.packages("MASS")
#install.packages("sandwich")
#install.packages("plm")
#install.packages("ggmap")
#install.packages("rgeos")
#install.packages("rgdal")
library(jsonlite)
library(dplyr)
library(foreign)
library(maptools)
library(foreign)
library(classInt)
library(RColorBrewer)
library(ggplot2)
library(plyr)
library(lsr)
library(bear)
library(MASS)
library(sandwich)
library(plm)
library(ggmap)
library(rgeos)
library(rgdal)
#http://data-analytics.net/cep/Schedule_files/geospatial.html
# MAPS VOTE #
communes=readOGR("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM/FRA_adm/FRA_adm5.shp")
communes_obf=read.dbf("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM/FRA_adm/FRA_adm5.dbf")
departements=readOGR("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM/FRA_adm/FRA_adm2.shp")
departements_obf=read.dbf("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM/FRA_adm/FRA_adm2.dbf")
regions=readOGR("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM/FRA_adm/FRA_adm1.shp")
data=read.dta("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM/Data_for_Maps_2711.dta")
#communes=readShapePoly("D:/Travail/Sciences Po/PhD/Paper 1/Carto/GEOFLA_2-0_COMMUNE_SHP_LAMB93_FXX_2015-07-01/GEOFLA/1_DONNEES_LIVRAISON_2015/GEOFLA_2-0_SHP_LAMB93_FR-ED151/COMMUNE/COMMUNE.SHP")
#communes_obf=read.dbf("D:/Travail/Sciences Po/PhD/Paper 1/Carto/GEOFLA_2-0_COMMUNE_SHP_LAMB93_FXX_2015-07-01/GEOFLA/1_DONNEES_LIVRAISON_2015/GEOFLA_2-0_SHP_LAMB93_FR-ED151/COMMUNE/COMMUNE.DBF")
#departements=readShapePoly("D:/Travail/Sciences Po/PhD/Paper 1/Carto/GEOFLA_1-1_SHP_LAMB93_FR-ED131_depa/GEOFLA_1-1_SHP_LAMB93_FR-ED131/GEOFLA/1_DONNEES_LIVRAISON_2013-11-00162/GEOFLA_1-1_SHP_LAMB93_FR-ED131/DEPARTEMENTS/DEPARTEMENT.SHP")
#departements_obf=read.dbf("D:/Travail/Sciences Po/PhD/Paper 1/Carto/GEOFLA_1-1_SHP_LAMB93_FR-ED131_depa/GEOFLA_1-1_SHP_LAMB93_FR-ED131/GEOFLA/1_DONNEES_LIVRAISON_2013-11-00162/GEOFLA_1-1_SHP_LAMB93_FR-ED131/DEPARTEMENTS/DEPARTEMENT.DBF")
#regions=readShapePoly("D:/Travail/Sciences Po/PhD/Conditions Locales - CEVIPOF/Cartes Départements/nouvelles_regions/nouvelles_regions.shp")
#data=read.dta("C:/Users/Paul/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data/Data_for_Maps_2711.dta")
communes_obf_data=merge(communes_obf,data, by.ID_5="INSEE_COM", by.NAME_5="com", all.ID_5=T)
communes_obf_data=merge(communes_obf,data, by.x="INSEE_COM", by.y="com", all.x=T)
setwd("D:/Dropbox/Migration and Extreme Votes in France - Max & Paul/Data and Codes for submission - PSRM")
library(jsonlite)
library(dplyr)
library(foreign)
library(maptools)
library(foreign)
library(classInt)
library(RColorBrewer)
library(ggplot2)
library(plyr)
library(lsr)
library(bear)
library(MASS)
library(sandwich)
library(plm)
library(ggmap)
library(rgeos)
library(rgdal)
#library(sf)
# MAPS VOTE #
communes=readShapePoly("COMMUNE.SHP")
communes_obf=read.dbf("COMMUNE.DBF")
regions=readShapePoly("nouvelles_regions.shp")
data=read.dta("Data_for_Maps_clean.dta")
communes_obf_data=merge(communes_obf,data, by.x="INSEE_COM", by.y="com", all.x=T)
communes_obf_data=communes_obf_data[order(communes_obf_data$ID_GEOFLA),]
# Vote LE PEN 2012
nclr=9
plotclr <- brewer.pal(9, "Purples")
plotvar <- communes_obf_data$fn_t1
class <- classIntervals(plotvar,nclr,style = "quantile",dataPrecision=2)
colcode <- findColours(class, plotclr)
jpeg(filename="Figure3a.jpg")
plot(communes, col=colcode, border="#00000000", add=F)
plot(regions, col="#00000000", border="black", add=T)
legend("bottomleft", legend = names(attr(colcode, "table")), border="#00000000", bty="n",  title = "Vote Le Pen (2012 - Round1)",fill = attr(colcode, "palette"),cex = 0.6)
dev.off()
# Vote LE PEN 2017
# Apply the values of 2017 to the deciles of 2012
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017<12.95,plotclr[1],"")
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=12.95 & communes_obf_data$voix_fn_t1_2017<15.69  ,plotclr[2],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=15.69 & communes_obf_data$voix_fn_t1_2017<17.98  ,plotclr[3],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=17.98 & communes_obf_data$voix_fn_t1_2017<20  ,plotclr[4],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=20 & communes_obf_data$voix_fn_t1_2017<22.06  ,plotclr[5],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=22.06 & communes_obf_data$voix_fn_t1_2017<24.15  ,plotclr[6],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=24.15  & communes_obf_data$voix_fn_t1_2017<26.62  ,plotclr[7],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=26.62  & communes_obf_data$voix_fn_t1_2017<30  ,plotclr[8],colcode3)
colcode3=ifelse(communes_obf_data$voix_fn_t1_2017>=30  ,plotclr[9],colcode3)
jpeg(filename="Figure3b.jpg")
plot(communes, col=colcode3, border="#00000000", add=F)
plot(regions, col="#00000000", border="black", add=T)
legend("bottomleft", legend = names(attr(colcode, "table")), border="#00000000", bty="n",  title = "Vote Le Pen (2017 - Round1)",fill = attr(colcode, "palette"),cex = 0.6)
dev.off()
